package edu.mapi.ir.viewer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.LinkedHashMap;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JPanel;

/**
 * @author ZP
 */
public class ScoreWall extends JPanel {
	
	private LinkedHashMap<String, ScorePanel> scores = new LinkedHashMap<String, ScorePanel>();
	private Timer t;
	private TimerTask updater = new TimerTask() {
		public void run() {
			repaint();
		}
	};
	public ScoreWall() {
		super();
		setLayout(new GridLayout(1,0));
		setPreferredSize(new Dimension(300,120));
		setMinimumSize(new Dimension(300,120));
		setBackground(Color.black);
		t= new Timer("Score updater");
		t.schedule(updater, 0, 100);
	}
	
	public void setMouse(MousePlayer mp) {
		String uid = mp.getPlayerName() + mp.getId();
		
		if (!scores.containsKey(uid)) {
			scores.put(uid, new ScorePanel(mp));
			add(scores.get(uid));
			revalidate();
		}
		
		scores.get(uid).update(mp);		
	}
	
	public void reset() {
		if (t != null)
			t.cancel();
		
		scores.clear();
		removeAll();
		revalidate();
		
	}
}
